package biz.obake.team.touchprotector.notice;

import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.b;
import biz.obake.team.touchprotector.g.c;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class a implements SharedPreferences.OnSharedPreferenceChangeListener, c.b {

    /* renamed from: c  reason: collision with root package name */
    private static a f1777c;

    /* renamed from: b  reason: collision with root package name */
    Map<String, Notice> f1778b = new HashMap();

    private a() {
        f();
        e();
        biz.obake.team.touchprotector.g.a.i().registerOnSharedPreferenceChangeListener(this);
        c.e(this);
    }

    public static a b() {
        if (f1777c == null) {
            f1777c = new a();
        }
        return f1777c;
    }

    private void e() {
        for (String str : new ArrayList(biz.obake.team.touchprotector.g.a.i().getAll().keySet())) {
            if (str.startsWith("notice_") && c(str.substring(7, 45)) == null) {
                biz.obake.team.touchprotector.g.a.n(str);
            }
        }
    }

    private void f() {
        XmlResourceParser xml = biz.obake.team.android.a.a().getResources().getXml(R.xml.ui_tab_notices);
        try {
            for (int eventType = xml.getEventType(); eventType != 1; eventType = xml.next()) {
                if (2 == eventType && "biz.obake.team.touchprotector.notice.NoticePreference".equals(xml.getName())) {
                    HashMap hashMap = new HashMap();
                    for (int i = 0; i < xml.getAttributeCount(); i++) {
                        String attributeNamespace = xml.getAttributeNamespace(i);
                        if ("http://schemas.android.com/apk/res/android".equals(attributeNamespace)) {
                            attributeNamespace = "android";
                        }
                        String attributeName = xml.getAttributeName(i);
                        String attributeValue = xml.getAttributeValue(i);
                        hashMap.put(attributeNamespace + ":" + attributeName, attributeValue);
                    }
                    String str = (String) hashMap.get(":class");
                    String str2 = (String) hashMap.get("android:key");
                    if (str == null || str2 == null) {
                        throw new b("{CC999841-2076-440B-A3E0-3BDC18578DC9}");
                    }
                    Notice notice = (Notice) Class.forName("biz.obake.team.touchprotector.notice." + str).newInstance();
                    notice.setAttributes(hashMap);
                    this.f1778b.put(str2, notice);
                }
            }
        } catch (Exception unused) {
        }
    }

    public int a() {
        int i = 0;
        StringBuilder sb = null;
        for (Notice next : this.f1778b.values()) {
            if (next.isAlerted()) {
                i++;
                if (sb == null) {
                    sb = new StringBuilder();
                } else {
                    sb.append(", ");
                }
                sb.append(next.mGuid);
            }
        }
        if (sb != null) {
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("Notice: " + sb.toString());
        }
        return i;
    }

    public Notice c(String str) {
        return this.f1778b.get(str);
    }

    public Collection<Notice> d() {
        return this.f1778b.values();
    }

    public void onRamPrefsChanged(String str) {
        for (Notice onRamPrefChanged : this.f1778b.values()) {
            onRamPrefChanged.onRamPrefChanged(str);
        }
    }

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
        for (Notice onPrefChanged : this.f1778b.values()) {
            onPrefChanged.onPrefChanged(str);
        }
    }
}
